package com.yitao.cms.service.expressage;

import com.querydsl.core.types.Order;
import com.querydsl.core.types.OrderSpecifier;
import com.skipper.base.data.querydsl.PredicateBuilder;
import com.skipper.base.service.GenericEntityService;
import com.yitao.client.dto.expressage.LogisticDetailDto;
import com.yitao.client.model.expressage.LogisticDetailModel;
import com.yitao.client.model.expressage.QLogisticDetailModel;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import java.util.ArrayList;
import java.util.List;

/**
 * 物流信息详情
 *
 * @Date: 2019/12/5 17:35
 * @Author: Kien
 */
@Service
public class LogisticDetailService  extends GenericEntityService<LogisticDetailModel, LogisticDetailDto, QLogisticDetailModel> {

    public LogisticDetailService(EntityManager entityManager) {
        super(entityManager);
    }

    /**
     *
     * 功能描述: 根据物流信息id获取轨迹列表
     * @param logisticHeadId 轨迹信息Id
     *
     * @return
     * @auther: Kien
     * @date: 2019/8/16 18:45
     */
    public List<LogisticDetailModel> findLogistaicDetailByTrackingId(Long logisticHeadId){
        if(null == logisticHeadId) {
            return new ArrayList<>();
        }
        return repository.findAll(PredicateBuilder.conjunction()
                .and(() -> Q.trackingId.eq(logisticHeadId))
                .get(), new OrderSpecifier<>(Order.DESC, Q.trackingTime));

    }
}
